#ifndef PLAYERCONTROLLER_H
#define PLAYERCONTROLLER_H

#include <csugl.h>
#include "ecs.h"

struct PlayerComponent : public Component
{
    PlayerComponent(float moveSpeed) : moveSpeed(moveSpeed) {}
    float moveSpeed;
};

struct PlayerController : public System
{
    PlayerController(csugl::Ref<Scene> cur_scene) : System(cur_scene) {}

    void update() override
    {
        _cur_scene->ComponentEach<PlayerComponent, TransformComponent>(
            [](const auto &player_c, auto &trans_c)
            {
                if (csugl::Input::IsKeyPressed(csugl::Key::A))
                {
                    trans_c.transform.position.x -= csugl::LowpTime::deltaTime() * player_c.moveSpeed;
                }
                if (csugl::Input::IsKeyPressed(csugl::Key::D))
                {
                    trans_c.transform.position.x += csugl::LowpTime::deltaTime() * player_c.moveSpeed;
                }
            });
    }
};

#endif